package com.qf.controller;

import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.service.DtsOrderService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import com.qf.vo.DayStatis;
import com.qf.vo.OrderAmtsVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * author:z
 * time:2021/12/1 9:32
 * description:
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/admin/stat")
public class AdminStatController {

    @Autowired
    DtsOrderService orderService;

    @Autowired
    DtsUserService userService;

    //定义常量 统计天数的范围。一个月数据
    private static final int STATIS_DAYS_RANG = 30;


    @RequestMapping("/order")
    public Object order() {
        Map data = new HashMap();
        String[] columns = {"day", "orders", "customers", "amount", "pcr"};
        data.put("columns", columns);
        List<Map> rows = orderService.queryRows(STATIS_DAYS_RANG);
        data.put("rows", rows);
        return ResponseUtil.ok(data);
    }

    @RequestMapping("/user")
    public Object user() {
        Map data = new HashMap();
        String[] columns = {"day", "users"};
        data.put("columns", columns);
        List<Map> rows = userService.queryRows(STATIS_DAYS_RANG);
        data.put("rows", rows);
        return ResponseUtil.ok(data);
    }
}
